@echo off
set help1=help:  capture_log type{hilog,dmesg} tag{event such as camera,start_up ...} project {zp37a,rk3568}
set help2=eg:    capture_log hilog camera_service zp37a
set logType=%1
set logTag=%2
set project=%3
echo commond is capture_log %logType% %logTag% %project%
if "%1" == "-h" (
    echo %help1%
    echo %help2%
    exit /b
)
if "%1" == "-c" (
    hdc shell hilog -r
    exit /b
)
if "%project%" == "" (
    set project=zp37a_
) else (
    set project=%3_
)
if "%logTag%" == "" (
    set logTag=
) else (
    set logTag=%logTag%_
)

if "%logType%" == "" (
    set logType=hilog_
) else (
    set logType=%logType%_
)
echo waiting for device
:listtargets
for /f "tokens=*" %%i in ('hdc list targets') do (
	@set device=%%i
)

if "%device%" == "[Empty]" (
    goto listtargets
)
echo device is %device%
echo capture_log start
set curTime=%date:~5,2%-%date:~8,2%_%time:~0,2%.%time:~3,2%.%time:~6,2%.%time:~9,2%
set curTime=%curTime: =%
set logfile=%project%%logTag%%logType%%curTime%.log
if "%logType%" == "dmesg_" (
    echo "hdc shell dmesg > %logfile%"
    hdc shell dmesg > %logfile%
) else (
    echo "hdc shell hilog > %logfile%"
    hdc shell hilog > %logfile%
)
